package com.ratta.supernote.note.plugincore.error;

/**
 * Installation failure information
 */
public class PluginException extends Throwable {

    public static enum PluginExceptionCode {
        unknownError(100, "Unknown error"),
        // Installation file format is incorrect
        installPluginFileError(101, "File is Wrong"),
        // Not a plugin zip package
        installPluginNotPluginZip(102, "Not plugin File Zip"),
        installPluginVersionLow(103, "Plugin Version is low"),
        // Error moving file during installation
        installPluginMoveError(104, "Error moving file during installation"),
        // Error extracting file
        installPluginUnzipError(105, "Error extracting file"),
        // Bundle file does not exist
        installBundleFileNotExists(106, "Bundle file does not exist"),
        // Failed to read Dex dependencies
        installReadDexFailed(107, "Failed to read Dex dependencies"),
        // System plugin already exists, do not install again
        installPluginExists(108, "System plugin already exists, do not install again"),
        installPluginNoSpace(109, "剩余空间不够，无法安装"),
        pluginZipNotExists(110, "安装的插件报不存在")
        ;

        int code;
        String message;

        PluginExceptionCode(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }

    private int errorCode;

    public int getErrorCode() {
        return errorCode;
    }

    public PluginException(PluginExceptionCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode.getCode();
    }

    public PluginException(int errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }
}
